package com.yunhe.mapper;

import com.yunhe.javabean.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RoleMapper {

    //查询所有角色
    @Select("select * from role")
    public List<Role> selectAll();

    //根据用户id查询对应角色信息
    @Select("select ur.userId,r.* from users_role ur,role r where ur.roleId=r.id and userId=#{userId}")
    public Role selectByUid(int uid);

    //根据角色id查询角色信息
    @Select("select * from role where id=#{id}")
    public Role selectById(int id);

    //修改角色信息
    @Update("update role set roleName=#{roleName},roleDesc=#{roleDesc} where id=#{id}")
    public int update(Role role);

    //添加角色信息
    @Insert("insert into role(roleName,roleDesc)values(#{roleName},#{roleDesc})")
    public int insert(Role role);

    //删除角色信息
    @Delete("delete from role where id=#{id}")
    public int deleteById(int id);

    //查询角色权限管理表中当前角色拥有的权限id集合
    @Select("select permissionId from role_permission where roleId=#{rid}")
    public List<Integer> selectAllPermissionId(int rid);


    //删除关联表中当前账号信息
    @Delete("delete from role_permission where roleId=#{rid}")
    public int deletePermissionByRId(int rid);

    //添加关联数据
    public int addPermissionByList(@Param("rid") Integer rid, @Param("ids") List<Integer> ids);


    //查询指定角色与权限信息
    public Role selectRole(int rid);



}
